package com.xqls.controller;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSONObject;
import com.xqls.biz.CompanyBiz;
import com.xqls.biz.DischargeRealdataBiz;
import com.xqls.biz.IntakeRealdataBiz;
import com.xqls.biz.PublicStormwaterRealdataBiz;
import com.xqls.biz.RainwaterDischargeRealdataBiz;
import com.xqls.biz.RemotecontrolBiz;
import com.xqls.dal.model.Remotecontrol;
import com.xqls.util.CommonResult;
import com.xqls.util.DictionaryEnums;

@Controller
@RequestMapping(value="/calibration")
public class CalibrationTimeController {
	@Autowired private IntakeRealdataBiz intakeRealdataBiz;
	@Autowired private DischargeRealdataBiz dischargeBiz;
	@Autowired private RainwaterDischargeRealdataBiz rainwaterBiz;
	@Autowired private PublicStormwaterRealdataBiz stormwaterBiz;
	@Autowired
	private CompanyBiz companyBiz;
	@Autowired private RemotecontrolBiz remoteBiz;
	@RequestMapping(value="/intakeCalibration")
	public  ModelAndView intakeCalibration(){
		ModelAndView view=new ModelAndView("calibration/intakeCalibrationTime");
		view.addObject("isCalibrationList", true);
		List<Map<String,Object>> intakeList = intakeRealdataBiz.queryAll();
		for (int i=0;i<intakeList.size();i++){
            intakeList.get(i).put("viewId",i+1);
		}
		view.addObject("intakeList", intakeList);
		view.addObject("title", "取水口时间校准");
		return view;
	}
	
	@RequestMapping(value = "/radioIntakeCalibration/{device_no}")
	public ModelAndView radioIntakeCalibration(@PathVariable(value = "device_no") String device_no) {
		ModelAndView view = new ModelAndView("calibration/intakeCalibrationTime");

		view.addObject("companyList", companyBiz.getList(DictionaryEnums.INTAKE));

		view.addObject("intake",intakeRealdataBiz.selectByDeviceNo(device_no));
		view.addObject("title", "取水口时间校准");
		return view;
	}
	
	@RequestMapping(value="/dischargeCalibration")
	public  ModelAndView dischargeCalibration(){
		ModelAndView view=new ModelAndView("calibration/dischargeCalibrationTime");
        List<Map<String,Object>> dischargeList = dischargeBiz.queryAll();
        for (int i=0;i<dischargeList.size();i++){
            dischargeList.get(i).put("viewId",i+1);
        }
		view.addObject("isCalibrationList", true);
		view.addObject("dischargeList", dischargeList);
		view.addObject("title", "排放口时间校准");
		return view;
		
	}
	
	@RequestMapping(value = "/radioDischargeCalibration/{device_no}")
	public ModelAndView radioDischargeCalibration(@PathVariable(value = "device_no") String device_no) {
		ModelAndView view = new ModelAndView("calibration/dischargeCalibrationTime");

		view.addObject("companyList", companyBiz.getList(DictionaryEnums.DISCHARGE));

		view.addObject("discharge",dischargeBiz.queryByDeviceNo(device_no));
		view.addObject("title", "排放口时间校准");
		return view;
	}
	@RequestMapping(value="/rainwaterCalibration")
	public  ModelAndView rainwaterCalibration(){
		ModelAndView view=new ModelAndView("calibration/rainwaterCalibrationTime");
        List<Map<String,Object>> rainwaterList = rainwaterBiz.queryAll();
        for (int i=0;i<rainwaterList.size();i++){
            rainwaterList.get(i).put("viewId",i+1);
        }
		view.addObject("isCalibrationList", true);
		view.addObject("rainwaterList", rainwaterList);
		view.addObject("title", "企业雨水排放口时间校准");
		return view;
		
	}
	
	@RequestMapping(value = "/radioRainwaterCalibration/{device_no}")
	public ModelAndView radioRainwaterCalibration(@PathVariable(value = "device_no") String device_no) {
		ModelAndView view = new ModelAndView("calibration/rainwaterCalibrationTime");

		view.addObject("companyList", companyBiz.getList(DictionaryEnums.RAINWATER));

		view.addObject("rainwater",rainwaterBiz.selectByDeviceNo(device_no));
		view.addObject("title", "企业雨水排放口时间校准");
		return view;
	}
	
	@RequestMapping(value="/stormwaterCalibration")
	public  ModelAndView stormwaterCalibration(){
		ModelAndView view=new ModelAndView("calibration/stormwaterCalibrationTime");
        List<Map<String,Object>> stormwaterList = stormwaterBiz.queryAll();
        for (int i=0;i<stormwaterList.size();i++){
            stormwaterList.get(i).put("viewId",i+1);
        }
		view.addObject("isCalibrationList", true);
		view.addObject("stormwaterList", stormwaterList);
		view.addObject("title", "公共雨水排放口时间校准");
		return view;
		
	}
	
	@RequestMapping(value = "/radioStormwaterCalibration/{device_no}")
	public ModelAndView radioStormwaterCalibration(@PathVariable(value = "device_no") String device_no) {
		ModelAndView view = new ModelAndView("calibration/stormwaterCalibrationTime");

		view.addObject("companyList", companyBiz.getList(DictionaryEnums.STORMWATER));

		view.addObject("stormwater",stormwaterBiz.selectByDeviceNo(device_no));
		view.addObject("title", "公共雨水排放口时间校准");
		return view;
	}
	
	@RequestMapping(value = "/send")
	@ResponseBody
	public CommonResult calibrationSend(String deviceSelect,Date time,String remoteType) {
		
		CommonResult commonResult=remoteBiz.calibration(deviceSelect, time,remoteType);
		
		return commonResult;

	}

}
